﻿// <copyright file="UniqueIDCopy.cs" company="Sinclair Community College">
// Copyright 2010 Sinclair Community College
// </copyright>
// <originalAuthor>Patrick S. Seymour (patrick.seymour@gmail.com)</originalAuthor>

namespace SinclairCC.AppV
{
    using System;

    /// <summary>
    /// This section of the CP file contains the copy of the unique identifier of the CP file,
    /// which is defined in the CP File Header Section field “Unique ID”).
    /// </summary>
    internal class UniqueIDCopy
    {
        /// <summary>
        /// The unique identifier of the CP file.
        /// </summary>
        private Guid id;

        /// <summary>
        /// Initializes a new instance of the UniqueIDCopy class.
        /// </summary>
        /// <param name="dataStream">
        /// A memory stream that contains the raw data for this section of the CP file.
        /// </param>
        public UniqueIDCopy(System.IO.MemoryStream dataStream)
        {
            this.ReadSection(dataStream);
        }

        /// <summary>
        /// Gets the unique identifier for the CP file.
        /// </summary>
        public Guid ID
        {
            get { return this.id; }
        }

        /// <summary>
        /// Reads the actual data for this section from the file.
        /// </summary>
        /// <param name="dataStream">
        /// A MemoryStream containing the raw data for the section.
        /// </param>
        private void ReadSection(System.IO.MemoryStream dataStream)
        {
            System.IO.BinaryReader streamReader = new System.IO.BinaryReader(dataStream);

            byte[] guidBytes = streamReader.ReadBytes(16);
            this.id = new Guid(guidBytes);

            streamReader.Close();
        }
    }
}
